import Vue from "vue";
import Router from "vue-router";
import { postMsgUtil } from "@ct/iframe-connect-sdk"; // 常用字典方法引入
import store from "../store";
Vue.use(Router);

export const constantRoutes = [
  {
    path: "/myEvent32",
    component: () => import("@/views/pages/eventManagement/myEvent/index.vue"),
    name: "/myEvent",
    meta: {
      title: "我的事件",
      icon: "home",
      noCache: false,
      affix: false,
      isKeepAlive: true,
    },
  },
  {
    path: "/eventLinks",
    component: () => import("@/views/pages/eventManagement/eventLinks.vue"),
    name: "/eventLinks",
    meta: {
      title: "事件环节",
      icon: "home",
      noCache: false,
      affix: false,
    },
  },
  // 事件查询
  {
    path: "/event",
    component: () => import("@/views/pages/eventManagement/eventManagement"),
    name: "/eventManagement",
    meta: {
      title: "事件查询",
      icon: "home",
      noCache: false,
      affix: false,
      isKeepAlive: true
    }
  },
];
console.log("constantRoutes", process.env);
const router = new Router({
  mode: "history", // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  base: process.env.VUE_APP_ROUTER_BASE,
  routes: constantRoutes,
});

router.beforeEach(async (to, from, next) => {
  // 给父窗体发送消息，检查是否跨域
  postMsgUtil.trigger(null, "middleLink", { url: "checkCross" });
  console.log("to", to, store.userPromise);
  store.userPromise.then(async () => {
    await store.dispatch("getPermissionsByTarget");
    next();
  });
});
export default router;
